

/*-------------------------------------------------------------------------
 *
 * smgrdesc.c
 *	  rmgr 描述例程，用于 catalog/storage.c
 *
 * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 *
 * IDENTIFICATION
 *	  src/backend/access/rmgrdesc/smgrdesc.c
 *
 *-------------------------------------------------------------------------
 */
#include "postgres.h"

#include "catalog/storage_xlog.h"


void smgr_desc(StringInfo fc_buf, XLogReaderState *fc_record)
{
	char	   *fc_rec = XLogRecGetData(fc_record);
	uint8		fc_info = XLogRecGetInfo(fc_record) & ~XLR_INFO_MASK;

	if (fc_info == XLOG_SMGR_CREATE)
	{
		xl_smgr_create *fc_xlrec = (xl_smgr_create *) fc_rec;
		char	   *fc_path = relpathperm(fc_xlrec->rnode, fc_xlrec->forkNum);

		appendStringInfoString(fc_buf, fc_path);
		pfree(fc_path);
	}
	else if (fc_info == XLOG_SMGR_TRUNCATE)
	{
		xl_smgr_truncate *fc_xlrec = (xl_smgr_truncate *) fc_rec;
		char	   *fc_path = relpathperm(fc_xlrec->rnode, MAIN_FORKNUM);

		appendStringInfo(fc_buf, "%s to %u blocks flags %d", fc_path,
						 fc_xlrec->blkno, fc_xlrec->flags);
		pfree(fc_path);
	}
}

const char * smgr_identify(uint8 fc_info)
{
	const char *fc_id = NULL;

	switch (fc_info & ~XLR_INFO_MASK)
	{
		case XLOG_SMGR_CREATE:
			fc_id = "CREATE";
			break;
		case XLOG_SMGR_TRUNCATE:
			fc_id = "TRUNCATE";
			break;
	}

	return fc_id;
}
